package cn.tedu.file;

import java.io.*;

/**本类用于测试字符输出流*/
public class TestOut2 {
    public static void main(String[] args) {
//        method1();
        method2();
    }

    private static void method2() {
        Writer out = null;
        try {
//            out = new BufferedWriter(new FileWriter(new File("F:\\ready\\1.txt")));
//            out = new BufferedWriter(new FileWriter("F:\\ready\\1.txt"));

//            out = new BufferedWriter(new FileWriter(new File("F:\\ready\\1.txt"),true));
            out = new BufferedWriter(new FileWriter("F:\\ready\\1.txt",true));

            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);
            out.write(98);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    private static void method1() {
        //1.定义局部变量
        Writer out = null;
        //2.完成异常捕获结构
        try{
            out = new FileWriter(new File("F:\\ready\\1.txt"));
            out = new FileWriter("F:\\ready\\1.txt");

//            out = new FileWriter(new File("F:\\ready\\1.txt"),true);
//            out = new FileWriter("F:\\ready\\1.txt",true);

            out.write(97);
            out.write(97);
            out.write(97);

        }catch(Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
